package com.my_musc_service.controller;

import com.github.pagehelper.PageInfo;
import com.my_musc_service.common.R;
import com.my_musc_service.entity.Songlist;
import com.my_musc_service.entity.SonglistVO;
import com.my_musc_service.service.SonglistService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Songlist)表控制层
 *
 * @author makejava
 * @since 2021-06-10 20:44:51
 * @description 歌单相关
 */
@RestController
@RequestMapping("songlist")
public class SonglistController {
    /**
     * 服务对象
     */
    @Resource
    private SonglistService songlistService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Songlist selectOne(Integer id) {
        return this.songlistService.queryById(id);
    }

    /**
     * 查询相应的信息
     *
     * @param songlist
     * @return
     */
    @GetMapping("select/all")
    public R getSonglistAll(Songlist songlist) {
        List<Songlist> songlists = songlistService.queryAll(songlist);
        return R.ok().data("songLists", songlists);
    }


    @PostMapping("select/page/{pageNo}/{pageSize}")
    public PageInfo<SonglistVO> getSonglistPageInfo(@PathVariable Integer pageNo, @PathVariable Integer pageSize, Songlist songlist) {
        PageInfo<SonglistVO> songlistPageInfo = songlistService.getSonglistPageInfo(pageNo, pageSize, songlist);
        return songlistPageInfo;
    }

    /**
     * 新增歌单
     *
     * @param songlist
     * @return
     */
    @PostMapping("add")
    public R addSonglist(@RequestBody Songlist songlist) {
        songlistService.insert(songlist);
        return R.ok();
    }

    /**
     * 删除歌单
     *
     * @param songlist
     * @return
     */
    @PostMapping("delete")
    public R deleteSonglist(@RequestBody Songlist songlist) {
        Integer rows = songlistService.deleteBySongList(songlist);
        return R.ok();
    }


}
